<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../vue.js"></script>
</head>

<body>
    <div class="app">
        <h1>{{title}}</h1>
        <parent></parent>
    </div>
    <template id="parent">
        <div>
            <h1>父元素的数据-{{name}}-{{age}}</h1>
            <childone @addage="addAge"></childone>
        </div>
    </template>
    <template id="childone">
        <div>
            <h3>子元素的数据</h3>
        <button @click="changeAge">点击修改父元素的数据</button>
        </div>
    </template>
</body>
<script>
    Vue.component("parent", {
        template: "#parent",
        data() {
            return {
                name: "可乐",
                age: 20
            }
        },
        methods: {
            addAge(n) {
                this.age += n
            }
        }
    })
    Vue.component("childone", {
        template: "#childone",
        data() {
            return {
                name: "不吃鱼的猫",
                age: 18
            }
        },
        methods: {
            changeAge() {
                //子元素发送事件
                this.$emit("addage", 5)
            }
        }
    })
    const vm = new Vue({
        data: {
            title: "字传父自定义事件"
        }
    }).$mount(".app")
</script>

</html>